using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class StorageDetailMap : EntityTypeConfiguration<StorageDetail>
    {
        public StorageDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.BillNumber)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("StorageDetail");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.OrderSummaryID).HasColumnName("OrderSummaryID");
            this.Property(t => t.BillNumber).HasColumnName("BillNumber");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Employee1ID).HasColumnName("Employee1ID");
            this.Property(t => t.Employee2ID).HasColumnName("Employee2ID");
            this.Property(t => t.Employee3ID).HasColumnName("Employee3ID");
            this.Property(t => t.DateOut).HasColumnName("DateOut");
            this.Property(t => t.WarehouseID).HasColumnName("WarehouseID");

            // Relationships
            this.HasOptional(t => t.Employee)
                .WithMany(t => t.StorageDetails)
                .HasForeignKey(d => d.Employee1ID);
            this.HasOptional(t => t.Employee1)
                .WithMany(t => t.StorageDetails1)
                .HasForeignKey(d => d.Employee2ID);
            this.HasOptional(t => t.Employee2)
                .WithMany(t => t.StorageDetails2)
                .HasForeignKey(d => d.Employee3ID);
            this.HasOptional(t => t.OrderSummary)
                .WithMany(t => t.StorageDetails)
                .HasForeignKey(d => d.OrderSummaryID);
            this.HasOptional(t => t.ProductModel)
                .WithMany(t => t.StorageDetails)
                .HasForeignKey(d => d.ProductModelID);
            this.HasOptional(t => t.Stock)
                .WithMany(t => t.StorageDetails)
                .HasForeignKey(d => d.WarehouseID);

        }
    }
}
